package com.ovidiojf.siesec.popule;

import static org.junit.Assert.*;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import com.ovidiojf.siesec.util.HibernateUtil;


public class ConexaoTest {

	private static Session session;
	private static Transaction transaction;
	
	@BeforeClass
	public static void abreConexao() {
		
		session = HibernateUtil.getSessionfactory().getCurrentSession();
		transaction = session.beginTransaction();
		
		assertTrue(transaction.isActive());
		
	}
	
	@AfterClass
	public static void fechaConexao() {
		try {
			transaction.commit();

		} catch (Throwable e) {
			System.out.println("Falha de commit: " + e.getMessage());
		} finally {
			try {
				if(session.isOpen())
					session.close();
		
			} catch (Exception e2) {
				System.out.println("Falha ao fechar sessão: " + e2.getMessage());
			}
		}
		
		assertFalse(transaction.isActive());
	}

}
